ON...GOSUB, ON...GOTO Statements ---------------------------------------------------------------------------- Action Branches to one of several specified lines, depending on the value of an expression. Syntax 1 ON expression GOSUB line-label-list Syntax 2 ON expression GOTO line-label-list Remarks The argument expression can be any numeric expression between 0 and 255, inclusive ( expression is rounded to an integer before the ON... GOSUB or ON... GOTO statement is evaluated). The argument line-label-list consists of a list of line numbers or line labels, separated by commas. The value of expression determines which line the program branches to. For example, if the value is 3, the third line specified in the list is the destination of the branch. The value of expression should be greater than or equal to 1 and less than or equal to the number of items in the list. If the value falls outside this range, one of the following results occurs. ----------------------------------------------------------------------------- Value Result ---------------------------------------------------------------------------- Number equal to 0 or greater than Control drops to the next BASIC number of items in list statement. Negative number or a number greater BASIC generates the error than 255 messageIllegal function call. You may mix line numbers and labels in the same list. Note You can mix line numbers and labels in the same list. The ON ... GOTO statement accepts a maximum of 60 line labels or line numbers. The SELECT CASE statement provides a more powerful, convenient, and flexible way to perform multiple branching. See Also GOSUB, RETURN, SELECT CASE Example The following example causes program control to branch to one of three subroutines, depending on the value of Chval. CLS ' Clear screen. Attend = 20 Fees = 5 * Attend PRINT "1 Display attendance at workshops" PRINT "2 Calculate total registration fees paid" PRINT "3 End program" PRINT . PRINT "What is your choice?" Choice. DO ch$ = INKEY$ LOOP WHILE ch$ = "" Chval = VAL(ch$) IF Chval > 0 AND Chval < 4 THEN ON Chval GOSUB Shop, Fees, Progend END IF END Shop. PRINT "ATTENDANCE IS", Attend RETURN Choice Fees. PRINT "REGISTRATION FEES ARE $"; Fees RETURN Choice Progend. END